<template>
  <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :close-on-click-modal="false" @close="closeDialog">
    <div style="display: flex;align-items: center;">
      <div class="span" style="margin-right: 8px;">刷新日志</div>
      <el-switch class="tableScopeSwitch1" :width="width" v-model="value" 
                 active-text="启用" :inline-prompt="true" inactive-text="禁止" @change="changeType" />
    </div>
  
    <ul v-infinite-scroll="load"
      style="width: 100%;background-color: rgba(0, 0, 0, 0.10);height: 300px;overflow: auto;padding:0 8px;">
      <ul class="infinite-list" style="width: 100%; min-height: 320px;padding-top: 8px;">
        <li v-for="item in contentList" style="display: block;margin-bottom: 8px;"> {{ item }} </li>
      </ul>
    </ul>
    <div slot="footer" class="dialog-footer">

      <el-button type="primary" :loading="loading" @click="dialogFormVisible = false">
        {{ $t('table.confirm') }}
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
import { createDataGovernanceTaskLog, updateDataGovernanceTaskLog, getDataGovernanceTaskLog } from '@/api/datagovernancetasklog/dataGovernanceTaskLog'

export default {
  name: 'DataGovernanceTaskLogForm',
  data() {
    return {
      rules: {
      },
      temp: {},
      textMap: {
        update: '编辑',
        create: '新建',
        look: '查看'
      },
      passobj: {
        fromLineNum: 0,
        logId: ''
      },
      contentList: [],
      loading: false,
      key: '',
      dialogFormVisible: false,
      dialogStatus: '',
      value:'false',
      width: 40,
      timekey:''
    }
  },
  updated(){
  
  },
  methods: {
    closeDialog(){
      clearInterval(this.timekey)
    },
    changeType(val){
      if(val){ 
        this.timekey=setInterval(()=>{
          this.load()
        },2000)
      }else{
      clearInterval(this.timekey)
      }
    },
    load() {
      if(!this.key){
        getDataGovernanceTaskLog(this.passobj).then(res => {
         
        if (res.data.code == 200) {
          this.contentList =[...this.contentList,...res.data.data.logContent]
          this.passobj.fromLineNum=res.data.data.toLineNum+1
          this.key=res.data.data.end
        }
      })
      }else{
       
      }
     
    },
    getList() {
      this.$emit('refreshList')
    },
    resetTemp() {
      this.loading = false
      this.temp = {
        id: undefined,
        status: undefined,
        executeJobId: undefined,
        executeDate: undefined,
        executeResult: undefined,
        tenantId: undefined
      }
    },
    getData() {
      getDataGovernanceTaskLog(this.passobj).then(res => {
         
        if (res.data.code == 200) {
          this.contentList = res.data.data.logContent
          this.passobj.fromLineNum=res.data.data.toLineNum+1
          this.key=res.data.data.end
        }
      })
    },
    handleUpdate(id) {
      this.resetTemp()
      this.passobj.logId = id
      this.passobj.fromLineNum=0
      this.dialogStatus = 'look'
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
      this.getData()
    },
    updateData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.loading = true
          updateDataGovernanceTaskLog(this.temp).then(response => {
            this.loading = false
            if (response.data.code === 0) {
              this.dialogFormVisible = false
              this.getList()
              this.$message.success(response.data.msg)
            } else {
              this.$message.error(response.data.msg)
            }
          })
        }
      })
    }
  }
}
</script>
<style>
#treeBox {
  margin-top: 1px;

  .el-table thead {
    display: none;
  }
}

.tableScopeSwitch1 .el-switch__label {
  position: absolute;
  display: none;
  color: #fff;
}

/*打开时文字位置设置*/
.tableScopeSwitch1 .el-switch__label--right {
  z-index: 1;
  right: -10px;
}

/*关闭时文字位置设置*/
.tableScopeSwitch1 .el-switch__label--left {
  z-index: 1;
  left: 20px;
}

/*显示文字*/
.tableScopeSwitch1 .el-switch__label.is-active {
  display: block;
}

.tableScopeSwitch1.el-switch .el-switch__core,
.el-switch .el-switch__label {
  width: 60px !important;
  /*开关按钮的宽度大小*/
}
.span{
  color: #606266;font-weight: 700;font-size: 14px;
}
</style>